babl-component.c \
babl-conversion.c \
babl-core.c \
- babl-cpuaccel.c \
babl-db.c \
babl-extension.c \
babl-fish-path.c \
babl-sanity.c \
babl-type.c \
babl-util.c \
+ babl-cpuaccel.c \
babl-version.c
h_sources = \
* to be iterated over, common functionality is defined through these
* macros.
*/
-#define BABL_CLASS_DECLARE(klass) \
- \
-Babl * babl_##klass##_from_id (int id); \
-void babl_##klass##_class_init (void); \
-void babl_##klass##_class_destroy (void); \
-void babl_##klass##_class_for_each (BablEachFunction each_fun, \
- void *user_data)
-
-/* If a class is declared as a "named class" it means it is a class
- * that has a specific name connected to it, that also allows defining
- * a new instance. These classes share common functionality with the
- * non_name classes but have two extra methods, the means to lookup by
- * name, as well as to create new named objects that later can be
- * looked up. These methods are babl_klass() babl_klass_new() but they
- * are declared outside of this macro.
- */
-#define BABL_NAMED_CLASS_DECLARE(klass) \
-BABL_CLASS_DECLARE (klass)
-
+#define BABL_CLASS_DECLARE(klass) \
+ \
+BablDb * babl_##klass##_db (void); \
+Babl * babl_##klass##_from_id (int id); \
+void babl_##klass##_class_for_each (BablEachFunction each_fun, \
+ void *user_data)
/* common header for any item inserted into database, the actual
* implementation of babl-instance is in babl-internal
#define _BABL_CLASSES_H
#include "babl-class.h"
+#include "babl-db.h"
/* magic number used at the start of all babl objects, used to do
* differentiation in polymorphic functions. (as well as manual type
BABL_SKY
};
-
#include "babl-type.h"
#include "babl-sampling.h"
#include "babl-component.h"
#include <stdarg.h>
-
-static int
-each_babl_component_destroy (Babl *babl,
- void *data)
-{
- babl_free (babl);
- return 0; /* continue iterating */
-}
-
static Babl *
component_new (const char *name,
int id,
/****************************************************************/
/* BablComponent */
-BABL_NAMED_CLASS_DECLARE (component);
+BABL_CLASS_DECLARE (component);
typedef struct
#include "babl-internal.h"
#include "babl-db.h"
-static int
-each_babl_conversion_destroy (Babl *babl,
- void *data)
-{
- babl_free (babl);
- return 0; /* continue iterating */
-}
-
static Babl *
conversion_new (const char *name,
int id,
#ifndef _BABL_CONVERSION_H
#define _BABL_CONVERSION_H
-BABL_NAMED_CLASS_DECLARE (conversion);
+BABL_CLASS_DECLARE (conversion);
Babl * babl_conversion (const char *name);
return babl_hash_by_int (htab, item->instance.id);
}
+static int
+each_free (Babl *data,
+ void *foo)
+{
+ babl_free (data);
+ return 0;
+}
+
+static int
+babl_db_destroy (void *data)
+{
+ BablDb *db = data;
+ babl_assert (db);
+
+ babl_db_each (db, each_free, NULL);
+ babl_mutex_destroy (db->mutex);
+ babl_free (db->name_hash);
+ babl_free (db->id_hash);
+ babl_free (db->babl_list);
+ return 0;
+}
+
BablDb *
babl_db_init (void)
{
BablDb *db = babl_calloc (sizeof (BablDb), 1);
+ babl_set_destructor (db, babl_db_destroy);
db->name_hash = babl_hash_table_init (db_hash_by_name, db_find_by_name);
db->id_hash = babl_hash_table_init (db_hash_by_id, db_find_by_id);
return db;
}
-void
-babl_db_destroy (BablDb *db)
-{
- babl_assert (db);
-
- babl_mutex_destroy (db->mutex);
- babl_hash_table_destroy (db->name_hash);
- babl_hash_table_destroy (db->id_hash);
- babl_list_destroy (db->babl_list);
- babl_free (db);
-}
Babl *
babl_db_find (BablDb *db,
BablDb *
babl_db_init (void);
-void
-babl_db_destroy (BablDb *db);
-
void
babl_db_each (BablDb *db,
BablEachFunction each_fun,
#include "config.h"
-#define BABL_PATH LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
-
-#define BABL_INIT_HOOK init_hook ();
-#define BABL_DESTROY_HOOK destroy_hook ();
#ifdef BABL_DYNAMIC_EXTENSIONS
/* must be defined before inclusion of babl-internal.h */
#include <string.h>
#include <stdarg.h>
-static int each_babl_extension_destroy (Babl *babl, void *data);
-
static Babl *babl_extension_current_extender = NULL;
Babl *
babl_extension_current_extender = new_extender;
}
+static int
+babl_extension_destroy (void *data);
+
static Babl *
extension_new (const char *path,
void *dl_handle,
Babl *babl;
babl = babl_malloc (sizeof (BablExtension) + strlen (path) + 1);
+ babl_set_destructor (babl, babl_extension_destroy);
babl->instance.name = (char *) babl + sizeof (BablExtension);
strcpy (babl->instance.name, path);
babl->instance.id = 0;
void (*destroy)(void) = NULL;
if (!db)
- db = babl_db_init ();
+ {
+ babl_extension_quiet_log ();
+ babl_set_extender (NULL);
+ db = babl_db_init ();
+ }
babl = extension_new ("BablBase",
dl_handle,
destroy);
return babl;
}
-static void
-init_hook (void)
-{
- babl_extension_quiet_log ();
- babl_set_extender (NULL);
-}
-
-static void
-destroy_hook (void)
+void babl_extension_deinit (void)
{
babl_free (babl_quiet);
babl_quiet = NULL;
{
if (babl)
{
- each_babl_extension_destroy (babl, NULL);
+ babl_free (babl);
}
babl_set_extender (NULL);
return NULL;
}
}
-static const char *
-babl_dir_list (void)
-{
- const char *ret;
-
- ret = getenv ("BABL_PATH");
- if (!ret)
- ret = BABL_PATH;
- return ret;
-}
-
static char *
expand_path (char *path)
{
/* parse the provided colon seperated list of paths to search
*/
-static void
+void
babl_extension_load_dir_list (const char *dir_list)
{
int eos = 0;
babl_free (path);
}
-static void
-dynamic_init_hook (void)
-{
- babl_extension_load_dir_list (babl_dir_list ());
-}
-
#endif
+
static int
-each_babl_extension_destroy (Babl *babl,
- void *data)
+babl_extension_destroy (void *data)
{
+ Babl *babl = data;
if (babl->extension.destroy)
babl->extension.destroy ();
if (babl->extension.dl_handle)
dlclose (babl->extension.dl_handle);
-
- babl_free (babl);
- return 0; /* continue iterating */
+ return 0;
}
BABL_CLASS_IMPLEMENT (extension)
/****************************************************************/
/* BablExtension */
-BABL_NAMED_CLASS_DECLARE (extension);
+BABL_CLASS_DECLARE (extension);
/*
* BablExtension objects are only used internally in babl.
*/
Babl * babl_extension (const char *name);
-
+void babl_extension_load_dir_list (const char *dir_list);
typedef struct
{
return buf;
}
+static int
+babl_fish_path_destroy (void *data)
+{
+ Babl *babl=data;
+ if (babl->fish_path.conversion_list)
+ babl_free (babl->fish_path.conversion_list);
+ babl->fish_path.conversion_list = NULL;
+ return 0;
+}
+
Babl *
babl_fish_path (const Babl *source,
const Babl *destination)
babl = babl_calloc (1, sizeof (BablFishPath) +
strlen (name) + 1);
+ babl_set_destructor (babl, babl_fish_path_destroy);
babl->class_type = BABL_FISH_PATH;
babl->instance.id = babl_fish_get_id (source, destination);
get_conversion_path (&pc, (Babl *) source, 0, max_path_length ());
babl_mutex_unlock (babl_format_mutex);
- babl_list_destroy (pc.current_path);
+ babl_free (pc.current_path);
}
if (babl_list_size (babl->fish_path.conversion_list) == 0)
{
- babl_list_destroy (babl->fish_path.conversion_list);
babl_free (babl);
return NULL;
}
#include <string.h>
#include <stdarg.h>
-
typedef struct _BablFindFish BablFindFish;
typedef struct _BablFindFish
find_memcpy_fish (Babl *item,
void *data);
-static int
-each_babl_fish_destroy (Babl *babl,
- void *data);
-
-
-/* ====================================== */
-
-
static int
find_fish_path (Babl *item,
void *data)
return id;
}
-BablDb *
-babl_fish_db (void)
-{
- if (!db)
- db = babl_db_init ();
- return db;
-}
-
Babl *
babl_fish (const void *source,
const void *destination)
}
}
-
-
-static int
-each_babl_fish_destroy (Babl *babl,
- void *data)
-{
- if (babl->class_type == BABL_FISH_PATH)
- babl_list_destroy (babl->fish_path.conversion_list);
- babl_free (babl);
- return 0; /* continue iterating */
-}
-
BABL_CLASS_MINIMAL_IMPLEMENT (fish);
babl_free (format->image_template);
format->image_template = NULL;
}
+ if (format->from_list)
+ babl_free (format->from_list);
return 0;
}
-static int
-each_babl_format_destroy (Babl *babl,
- void *data)
-{
- if (babl->format.from_list)
- babl_list_destroy (babl->format.from_list);
- babl_free (babl);
-
- return 0; /* continue iterating */
-}
-
static Babl *
format_new (const char *name,
int id,
#ifndef _BABL_FORMAT_H
#define _BABL_FORMAT_H
-BABL_NAMED_CLASS_DECLARE (format);
+BABL_CLASS_DECLARE (format);
typedef struct
{
return htab->mask + 1;
}
+
+static int
+babl_hash_table_destroy (void *data)
+{
+ BablHashTable *htab = data;
+ babl_free (htab->data_table);
+ babl_free (htab->chain_table);
+ return 0;
+}
+
+
BablHashTable *
babl_hash_table_init (BablHashValFunction hfunc,
BablHashFindFunction ffunc)
babl_assert(ffunc);
htab = babl_calloc (sizeof (BablHashTable), 1);
- babl_assert (htab);
+ babl_set_destructor (htab, babl_hash_table_destroy);
htab->data_table = NULL;
htab->chain_table = NULL;
return htab;
}
-void
-babl_hash_table_destroy (BablHashTable *htab)
-{
- babl_assert (htab);
-
- babl_free (htab->data_table);
- babl_free (htab->chain_table);
- babl_free (htab);
-}
-
int
babl_hash_table_insert (BablHashTable *htab,
Babl *item)
BablHashFindFunction find_func,
void *data);
-void
-babl_hash_table_destroy (BablHashTable *htab);
-
-
#endif
babl = image_new (format, model, components, component, sampling, type, data, pitch, stride);
return babl;
}
-
-void
-babl_image_class_destroy (void)
-{
- /* nothing to do */
-}
-
-void
-babl_image_class_init (void)
-{
- /* nothing to do */
-}
#include "babl.h"
#define _BABL_INTERNAL_H
-#include "babl-class.h"
#include "babl-classes.h"
#include "babl-introspect.h"
+#include "babl-class.h"
#include "babl-list.h"
#include "babl-hash-table.h"
#include "babl-db.h"
void babl_set_extender (Babl *new_extender);
Babl * babl_extension_quiet_log (void);
+void babl_extension_deinit (void);
long babl_fish_reference_process (Babl *babl,
BablImage *source,
BablImage *destination,
long n);
-BablDb * babl_fish_db (void);
Babl * babl_fish_reference (const Babl *source,
const Babl *destination);
Babl * babl_fish_simple (BablConversion *conversion);
void babl_internal_destroy (void);
-#ifndef BABL_INIT_HOOK
-#define BABL_INIT_HOOK
-#endif
-#ifndef BABL_PRE_INIT_HOOK
-#define BABL_PRE_INIT_HOOK
-#endif
-#ifndef BABL_DESTROY_HOOK
-#define BABL_DESTROY_HOOK
-#endif
-#ifndef BABL_DESTROY_PRE_HOOK
-#define BABL_DESTROY_PRE_HOOK
-#endif
-
/* this template is expanded in the files including babl-internal.h,
* generating code, the declarations for these functions are found in
* the BABL_CLASS expansions done in babl.h as well, thus babl.h needs
*/
#define BABL_CLASS_MINIMAL_IMPLEMENT(klass) \
-void \
-babl_##klass##_class_init (void) \
+ \
+BablDb * \
+babl_##klass##_db (void) \
{ \
- BABL_PRE_INIT_HOOK; \
if (!db) \
db=babl_db_init (); \
- BABL_INIT_HOOK; \
-} \
- \
-void \
-babl_##klass##_class_destroy (void) \
-{ \
- BABL_DESTROY_PRE_HOOK; \
- babl_db_each (db,each_babl_##klass##_destroy, NULL); \
- babl_db_destroy (db); \
- BABL_DESTROY_HOOK; \
+ return db; \
} \
\
void \
babl_fatal ("%s(%i): not found", G_STRFUNC, id); \
} \
return babl; \
-}
+} \
#define BABL(obj) ((Babl*)(obj))
return babl_list_init_with_size (BABL_LIST_INITIAL_SIZE);
}
+static int
+babl_list_destroy (void *data)
+{
+ BablList *list = data;
+ babl_free (list->items);
+ return 0;
+}
+
BablList *
babl_list_init_with_size (int initial_size)
{
BablList *list = babl_calloc (sizeof (BablList), 1);
- babl_assert (list);
+ babl_set_destructor (list, babl_list_destroy);
if (initial_size == 0)
initial_size = 1;
return list;
}
-void
-babl_list_destroy (BablList *list)
-{
- babl_assert (list);
-
- babl_free (list->items);
- babl_free (list);
-}
-
void
babl_list_insert_last (BablList *list,
Babl *item)
BablList *
babl_list_init_with_size (int initial_size);
-void
-babl_list_destroy (BablList *list);
-
int
babl_list_size (BablList *list);
#include "babl-internal.h"
#include "babl-db.h"
-
static int
-each_babl_model_destroy (Babl *babl,
- void *data)
+babl_model_destroy (void *data)
{
+ Babl *babl = data;
if (babl->model.from_list)
- babl_list_destroy (babl->model.from_list);
- babl_free (babl);
- return 0; /* continue iterating */
+ babl_free (babl->model.from_list);
+ return 0;
}
static char *
babl = babl_malloc (sizeof (BablModel) +
sizeof (BablComponent *) * (components) +
strlen (name) + 1);
+ babl_set_destructor (babl, babl_model_destroy);
babl->model.component = (void *) (((char *) babl) + sizeof (BablModel));
babl->instance.name = (void *) (((char *) babl->model.component) + sizeof (BablComponent *) * (components));
#ifndef _BABL_MODEL_H
#define _BABL_MODEL_H
-BABL_NAMED_CLASS_DECLARE (model);
+BABL_CLASS_DECLARE (model);
typedef struct
{
each_babl_sampling_destroy (Babl *babl,
void *data)
{
- if (babl->sampling.from_list)
- babl_list_destroy (babl->sampling.from_list);
- return 0; /* continue iterating */
+ return 0;
}
void
typedef struct
{
BablInstance instance;
- BablList *from_list;
int horizontal;
int vertical;
char name[4];
} BablSampling;
+void
+babl_sampling_class_init (void);
+
#endif
#include "babl-internal.h"
#include "babl-db.h"
-
static int
-each_babl_type_destroy (Babl *babl,
- void *data)
+babl_type_destroy (void *data)
{
+ Babl *babl = data;
if (babl->type.from_list)
- babl_list_destroy (babl->type.from_list);
- babl_free (babl);
- return 0; /* continue iterating */
+ babl_free (babl->type.from_list);
+ return 0;
}
-
static Babl *
type_new (const char *name,
int id,
babl_assert (bits % 8 == 0);
babl = babl_malloc (sizeof (BablType) + strlen (name) + 1);
+ babl_set_destructor (babl, babl_type_destroy);
babl->instance.name = (void *) ((char *) babl + sizeof (BablType));
babl->class_type = BABL_TYPE;
babl->instance.id = id;
#ifndef _BABL_TYPE_H
#define _BABL_TYPE_H
-BABL_NAMED_CLASS_DECLARE (type);
+BABL_CLASS_DECLARE (type);
typedef struct
{
static int ref_count = 0;
+#define BABL_PATH LIBDIR BABL_DIR_SEPARATOR BABL_LIBRARY
+
+static const char *
+babl_dir_list (void)
+{
+ const char *ret;
+
+ ret = getenv ("BABL_PATH");
+ if (!ret)
+ ret = BABL_PATH;
+ return ret;
+}
+
void
babl_init (void)
{
if (ref_count++ == 0)
{
babl_internal_init ();
- babl_type_class_init ();
babl_sampling_class_init ();
- babl_component_class_init ();
- babl_model_class_init ();
- babl_format_class_init ();
- babl_conversion_class_init ();
+ babl_type_db ();
+ babl_component_db ();
+ babl_model_db ();
+ babl_format_db ();
+ babl_conversion_db ();
+ babl_extension_db ();
+ babl_fish_db ();
babl_core_init ();
babl_sanity ();
babl_extension_base ();
babl_sanity ();
- babl_extension_class_init ();
- babl_sanity ();
- babl_fish_class_init ();
- babl_sanity ();
+
+ babl_extension_load_dir_list (babl_dir_list ());
}
}
}
}
- babl_extension_class_destroy ();
- babl_fish_class_destroy ();
- babl_conversion_class_destroy ();
- babl_format_class_destroy ();
- babl_model_class_destroy ();
- babl_component_class_destroy ();
- babl_sampling_class_destroy ();
- babl_type_class_destroy ();
+ babl_extension_deinit ();
+ babl_free (babl_extension_db ());;
+ babl_free (babl_fish_db ());;
+ babl_free (babl_conversion_db ());;
+ babl_free (babl_format_db ());;
+ babl_free (babl_model_db ());;
+ babl_free (babl_component_db ());;
+ babl_free (babl_type_db ());;
+
babl_internal_destroy ();
#if BABL_DEBUG_MEM
babl_memory_sanity ();